package easycloud.ecs.web.controller;

import javax.inject.Inject;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import easycloud.ecs.common.domain.Item;
import easycloud.ecs.web.exception.DomainNotFoundException;
import easycloud.ecs.web.service.ItemService;

@Controller
@RequestMapping("item")
public class ItemController extends BaseController {
	private static final Log logger = LogFactory.getLog(ItemController.class);

	@Inject
	private ItemService itemService;

	@RequestMapping(value = "{itemId}")
	public ModelAndView detail(@PathVariable("itemId") Integer itemId) {
		ModelAndView mav = new ModelAndView("item.detail");
		Item item = itemService.getItem(itemId);
		if (item == null) {
			throw new DomainNotFoundException(Item.class, itemId);
		}

		mav.addObject("item", item);
		return mav;
	}
}
